<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>ueditor图片对话框</title>
    <script type="text/javascript" src="../internal.js"></script>

    <!-- jquery -->
    <script
      type="text/javascript"
      src="../../third-party/jquery-1.10.2.min.js"
    ></script>

    <!-- webuploader -->
    <script src="../../third-party/webuploader/webuploader.min.js"></script>
    <link
      rel="stylesheet"
      type="text/css"
      href="../../third-party/webuploader/webuploader.css"
    />
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    

    <!-- image dialog -->
    <link rel="stylesheet" href="image.css" type="text/css" />
  </head>
  <body>
    <div class="wrapper">
      <div id="tabhead" class="tabhead">
        <span class="tab" data-content-id="remote"
          ><var id="lang_tab_remote"></var
        ></span>
        <!-- <span class="tab focus" data-content-id="upload"><var id="lang_tab_upload"></var></span>
            <span class="tab" data-content-id="online"><var id="lang_tab_online"></var></span>
            <span class="tab" data-content-id="search"><var id="lang_tab_search"></var></span> -->
        <span class="tab" data-content-id="search">
          <input class="imp_img" type="file" />
        </span>
      </div>
      <div class="alignBar">
        <label class="algnLabel"><var id="lang_input_align"></var></label>
        <span id="alignIcon">
          <span
            id="noneAlign"
            class="none-align focus"
            data-align="none"
          ></span>
          <span id="leftAlign" class="left-align" data-align="left"></span>
          <span id="rightAlign" class="right-align" data-align="right"></span>
          <span
            id="centerAlign"
            class="center-align"
            data-align="center"
          ></span>
        </span>
        <input id="align" name="align" type="hidden" value="none" />
      </div>
      <div id="tabbody" class="tabbody">
        <!-- 远程图片 -->
        <div id="remote" class="panel">
          <div class="top">
            <div class="row">
              <label for="url"><var id="lang_input_url"></var></label>
              <span><input class="text" id="url" type="text"/></span>
            </div>
          </div>
          <div class="left">
            <div class="row">
              <label><var id="lang_input_size"></var></label>
              <span
                ><var id="lang_input_width">&nbsp;&nbsp;</var
                ><input class="text" type="text" id="width" value="100"/>%
              </span>
              <span
                ><var id="lang_input_height">&nbsp;&nbsp;</var
                ><input class="text" type="text" id="height" value="100"/>%
              </span>
              <span
                ><input id="lock" style="display: none;" type="checkbox" disabled="disabled"/><span
                  id="lockicon"
                ></span
              ></span>
            </div>
            <div class="row">
              <label><var id="lang_input_border"></var></label>
              <span><input class="text" type="text" id="border" /> </span>
            </div>
            <div class="row">
              <label><var id="lang_input_vhspace"></var></label>
              <span><input class="text" type="text" id="vhSpace" /> </span>
            </div>
            <div class="row">
              <label><var id="lang_input_title"></var></label>
              <span><input class="text" type="text" id="title"/></span>
            </div>
          </div>
          <div class="right"><div id="preview"></div></div>
        </div>

        <!-- 上传图片 -->
        <div id="upload" class="panel focus">
          <div id="queueList" class="queueList">
            <div class="statusBar element-invisible">
              <div class="progress">
                <span class="text">0%</span>
                <span class="percentage"></span>
              </div>
              <div class="info"></div>
              <div class="btns">
                <div id="filePickerBtn"></div>
                <div class="uploadBtn"><var id="lang_start_upload"></var></div>
              </div>
            </div>
            <div id="dndArea" class="placeholder">
              <div class="filePickerContainer">
                <div id="filePickerReady"></div>
              </div>
            </div>
            <ul class="filelist element-invisible">
              <li id="filePickerBlock" class="filePickerBlock"></li>
            </ul>
          </div>
        </div>

        <!-- 在线图片 -->
        <div id="online" class="panel">
          <div id="imageList"><var id="lang_imgLoading"></var></div>
        </div>

        <!-- 搜索图片 -->
        <div id="search" class="panel">
          <div class="searchBar">
            <input id="searchTxt" class="searchTxt text" type="text" />
            <select id="searchType" class="searchType">
              <option value="&s=4&z=0"></option>
              <option value="&s=1&z=19"></option>
              <option value="&s=2&z=0"></option>
              <option value="&s=3&z=0"></option>
            </select>
            <input id="searchReset" type="button" />
            <input id="searchBtn" type="button" />
          </div>
          <div id="searchList" class="searchList">
            <ul id="searchListUl"></ul>
          </div>
        </div>
      </div>
    </div>
    <script type="text/javascript" src="image.js"></script>
    <script type="text/javascript">
      // 文件服务器地址(信息发布)
      var myImgUrl = localStorage.getItem("imgUrl") + "/fileService/fileUpload";
      // vue调用后端服务器ip+端口
      var target = localStorage.getItem("target");
      // 是否加wxmanage
      var firstUrl = localStorage.getItem("firstUrl");
      // 是哪一个页面（信息发布or新闻发布）调用该子页面
      var editorType = localStorage.getItem("editorType");

      $(".imp_img").change(function(e) {
        console.log(e.target.files[0]);
        if (editorType == "message") {
          getFtoken(e.target.files[0], "content");
        } else if (editorType == "news") {
          getNewsImgUrl(e.target.files[0]);
        }
      });

      // 获取ftoken (信息发布获取图片地址方法)
      function getFtoken(file, type) {
        console.log(file);
        let params = {
          //接口入参
          token: sessionStorage.getItem("token"),
          data: {}
        };
        let RequestObj = {
          url: target + firstUrl + "/file/getFtoken",
          // url: 'http://192.168.0.91:9992/fileService/fileUpload',//赤壁水司
          method: "post",
          timeout: 60000,
          headers: {
            "Content-Type": "application/json",
            "Access-Control-Allow-Origin": "*"
          },
          withCredentials: true,
          data: params
        };
        axios(RequestObj).then(res => {
          console.log(res);

          let formData = new FormData();
          formData.append("file", file);
          formData.append("ftoken", res.data.data.ftoken);
          let RequestObj = {
            url: myImgUrl,
            // url: 'http://192.168.0.91:9992/fileService/fileUpload',//赤壁水司
            method: "post",
            timeout: 60000,
            headers: { "Content-Type": "application/json" },
            withCredentials: true,
            data: formData
          };
          axios(RequestObj)
            .then(
              res => {
                if (res.status === 200) {
                  if (res.data.code === 0) {
                    var div = localStorage.getItem("imgUrl") + "/fileService/fileDownload?path=" + res.data.data.path;
                    $("#url").val(div);
                  }
                }
              },
              err => {}
            )
            .catch(error => {});
        }).catch(err => {
          alert(res.data.description)
        })
      }
      // 新闻发布获取图片地址方法
      function getNewsImgUrl(file) {
        let formData = new FormData();
        formData.append("multipartFile", file);
        formData.append("token", sessionStorage.getItem("token"));
        let RequestObj = {
          url: target + firstUrl + "/news/contentMediaUrl.api",
          method: "post",
          timeout: 60000,
          headers: { "Content-Type": "application/json" },
          withCredentials: true,
          data: formData
        };
        axios(RequestObj)
            .then(
              res => {
                if (res.status === 200) {
                  if (res.data.code === 0) {
                    // var div = localStorage.getItem("imgUrl") + "/fileService/fileDownload?path=" + res.data.data.path;
                    $("#url").val(res.data.data);
                  }
                }
              },
              err => {}
            )
            .catch(error => {
              alert(res.data.description)
            });
      }
    </script>
  </body>
</html>
